From b4df69d89b25c8129901e9a825d55b64ed94cea8 Mon Sep 17 00:00:00 2001
From: tsteven4 <13596209+tsteven4@users.noreply.github.com>
Date: Thu, 4 Aug 2022 11:39:14 -0600
Subject: [PATCH] retire html_entitize, xml_entitize. (#906)
* retire html_entitize, xml_entitize.
in favor of QString::toHtmlEscaped() and XmlStreamWriter.
* delete obsolete entity struct.
---
defs.h | 2 -
html.cc | 10 ++---
kml.cc | 2 +-
util.cc | 114 --------------------------------------------------------
4 files changed, 6 insertions(+), 122 deletions(-)
diff --git a/defs.h b/defs.h
index b7d1fc246..5c88eb486 100644
--- a/defs.h
+++ b/defs.h
@@ -1079,8 +1079,6 @@ QDateTime dotnet_time_to_qdatetime(long long dotnet);
QString get_cache_icon(const Waypoint* waypointp);
QString gs_get_cachetype(geocache_type t);
QString gs_get_container(geocache_container t);
-[[deprecated("Use xmlstreamwriter.")]] QString xml_entitize(const QString& str);
-QString html_entitize(const QString& str);
QString strip_html(const utf_string*);
QString strip_nastyhtml(const QString& in);
QString convert_human_date_format(const char* human_datef); /* "MM,YYYY,DD" -> "%m,%Y,%d" */
diff --git a/html.cc b/html.cc
index 0359a49a2..19cebca01 100644
--- a/html.cc
+++ b/html.cc
@@ -96,9 +96,9 @@ HtmlFormat::html_disp(const Waypoint* wpt) const
if (wpt->description != wpt->shortname) {
if (wpt->HasUrlLink()) {
*file_out << "GetUrlLink().url_ << "\">"
- << html_entitize(wpt->description) << "";
+ << wpt->description.toHtmlEscaped() << "";
} else {
- *file_out << html_entitize(wpt->description);
+ *file_out << wpt->description.toHtmlEscaped();
}
if (!wpt->gc_data->placer.isEmpty()) {
*file_out << " by " << wpt->gc_data->placer;
@@ -162,7 +162,7 @@ HtmlFormat::html_disp(const Waypoint* wpt) const
logpart = xml_findfirst(curlog, "groundspeak:finder");
if (logpart) {
*file_out << ""
- << html_entitize(logpart->cdata) << " on ";
+ << logpart->cdata.toHtmlEscaped() << " on ";
}
logpart = xml_findfirst(curlog, "groundspeak:date");
@@ -197,7 +197,7 @@ HtmlFormat::html_disp(const Waypoint* wpt) const
s = logpart->cdata;
}
- *file_out << html_entitize(s);
+ *file_out << s.toHtmlEscaped();
}
*file_out << "
\n";
@@ -215,7 +215,7 @@ void
HtmlFormat::html_index(const Waypoint* wpt) const
{
*file_out << " "
- << html_entitize(wpt->shortname) << " - " << html_entitize(wpt->description)
+ << wpt->shortname.toHtmlEscaped() << " - " << wpt->description.toHtmlEscaped()
<< "
\n";
}
diff --git a/kml.cc b/kml.cc
index bf56c1dff..9dc7ee3b8 100644
--- a/kml.cc
+++ b/kml.cc
@@ -1239,7 +1239,7 @@ QString KmlFormat::kml_geocache_get_logs(const Waypoint* wpt) const
}
r += "
";
- r += html_entitize(s);
+ r += s.toHtmlEscaped();
}
r += "";
diff --git a/util.cc b/util.cc
index 02ecbd53c..eeccc39fd 100644
--- a/util.cc
+++ b/util.cc
@@ -1354,120 +1354,6 @@ strip_html(const utf_string* in)
#endif
}
-struct entity_types {
- const char* text;
- const char* entity;
- int not_html;
-};
-
-static
-entity_types stdentities[] = {
- { "&", "&", 0 },
- { "'", "'", 1 },
- { "<", "<", 0 },
- { ">", ">", 0 },
- { "\"", """, 0 },
- { "\x01", " ", 1 }, // illegal xml 1.0 character
- { "\x02", " ", 1 }, // illegal xml 1.0 character
- { "\x03", " ", 1 }, // illegal xml 1.0 character
- { "\x04", " ", 1 }, // illegal xml 1.0 character
- { "\x05", " ", 1 }, // illegal xml 1.0 character
- { "\x06", " ", 1 }, // illegal xml 1.0 character
- { "\x07", " ", 1 }, // illegal xml 1.0 character
- { "\x08", " ", 1 }, // illegal xml 1.0 character
- // { "\x09", " ", 1 }, legal xml 1.0 character
- // { "\x0a", " ", 1 }, legal xml 1.0 character
- { "\x0b", " ", 1 }, // illegal xml 1.0 character
- { "\x0c", " ", 1 }, // illegal xml 1.0 character
- // { "\x0d", " ", 1 }, legal xml 1.0 character
- { "\x0e", " ", 1 }, // illegal xml 1.0 character
- { "\x0f", " ", 1 }, // illegal xml 1.0 character
- { "\x10", " ", 1 }, // illegal xml 1.0 character
- { "\x11", " ", 1 }, // illegal xml 1.0 character
- { "\x12", " ", 1 }, // illegal xml 1.0 character
- { "\x13", " ", 1 }, // illegal xml 1.0 character
- { "\x14", " ", 1 }, // illegal xml 1.0 character
- { "\x15", " ", 1 }, // illegal xml 1.0 character
- { "\x16", " ", 1 }, // illegal xml 1.0 character
- { "\x17", " ", 1 }, // illegal xml 1.0 character
- { "\x18", " ", 1 }, // illegal xml 1.0 character
- { "\x19", " ", 1 }, // illegal xml 1.0 character
- { "\x1a", " ", 1 }, // illegal xml 1.0 character
- { "\x1b", " ", 1 }, // illegal xml 1.0 character
- { "\x1c", " ", 1 }, // illegal xml 1.0 character
- { "\x1d", " ", 1 }, //illegal xml 1.0 character
- { "\x1e", " ", 1 }, //illegal xml 1.0 character
- { "\x1f", " ", 1 }, //illegal xml 1.0 character
- { nullptr, nullptr, 0 }
-};
-
-static
-QString
-entitize(const char* str, bool is_html)
-{
- char* p;
- char* tmp;
- char* xstr;
-
- entity_types* ep = stdentities;
- int elen = 0;
- int ecount = 0;
-
- /* figure # of entity replacements and additional size. */
- while (ep->text) {
- const char* cp = str;
- while ((cp = strstr(cp, ep->text)) != nullptr) {
- elen += strlen(ep->entity) - strlen(ep->text);
- ecount++;
- cp += strlen(ep->text);
- }
- ep++;
- }
-
- /* enough space for the whole string plus entity replacements, if any */
- tmp = (char*) xcalloc((strlen(str) + elen + 1), 1);
- strcpy(tmp, str);
-
- if (ecount != 0) {
- for (ep = stdentities; ep->text; ep++) {
- p = tmp;
- if (is_html && ep->not_html) {
- continue;
- }
- while ((p = strstr(p, ep->text)) != nullptr) {
- elen = strlen(ep->entity);
-
- xstr = xstrdup(p + strlen(ep->text));
-
- strcpy(p, ep->entity);
- strcpy(p + elen, xstr);
-
- xfree(xstr);
-
- p += elen;
- }
- }
- }
-
- QString rv(tmp);
- xfree(tmp);
- return rv;
-}
-
-/*
- * Public callers for the above to hide the absence of &apos from HTML
- */
-
-[[deprecated("Use xmlstreamwriter.")]] QString xml_entitize(const QString& str)
-{
- return entitize(CSTR(str), false);
-}
-
-QString html_entitize(const QString& str)
-{
- return entitize(CSTR(str), true);
-}
-
/*
* xml_tag utilities
*/
--
2.30.2